/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.entity;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

/**
 *
 * @author andrea
 */
@Entity
@IdClass(InvitationKey.class)
public class Invitation implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @NotNull
    @ManyToOne
    @JoinColumn(referencedColumnName = "email")
    private Users user;    
    
    @Id
    @NotNull
    @ManyToOne
    @JoinColumn(referencedColumnName = "id")
    private Event event;    
    @NotNull
    @Enumerated
    private Status status;
    
    public Invitation(){
        status = Status.PENDING;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Invitation other = (Invitation) obj;
        if (!Objects.equals(this.user, other.user)) {
            return false;
        }
        return Objects.equals(this.event, other.event);
    }    
    
    @Override
    public String toString() {
        return String.format("User %s %s invited to the event %s",user.getName(),user.getSurname(),event.getTitle());
    }
    
}